package com.kaifamiao.converter;

import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.databind.util.Converter;

import java.time.LocalDate;
import java.util.logging.Logger;

public class LocalDateConverter implements Converter<String, LocalDate> {

    private Logger logger = Logger.getLogger( this.getClass().getName() );

    @Override
    public LocalDate convert(String source) {
        logger.info( "将" + source + "解析为 LocalDate" );
        return LocalDate.parse( source );
    }

    @Override
    public JavaType getInputType(TypeFactory typeFactory) {
        return typeFactory.constructType(String.class);
    }

    @Override
    public JavaType getOutputType(TypeFactory typeFactory) {
        return typeFactory.constructType(LocalDate.class);
    }

}
